package org.homeworkadmin.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.homeworkadmin.admin.service.PostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.homeworkadmin.common.annotation.Log;
import org.homeworkadmin.common.core.controller.BaseController;
import org.homeworkadmin.common.core.domain.AjaxResult;
import org.homeworkadmin.common.enums.BusinessType;
import org.homeworkadmin.admin.domain.Post;
import org.homeworkadmin.common.utils.poi.ExcelUtil;
import org.homeworkadmin.common.core.page.TableDataInfo;

/**
 * 帖子管理Controller
 *
 * @author ruoyi
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/post")
public class PostController extends BaseController
{
    @Autowired
    private PostService postService;

    @GetMapping("/getPost")
    public AjaxResult getPost(String postType,int pagesize,int currpage)
    {
        currpage = (currpage-1) * pagesize;
        int total = postService.getPostCount(postType);
        List<Post> list = postService.getPost(postType,pagesize,currpage);
        list.forEach(post -> {
            post.setPostPhoto("http://localhost:8007/img/get?url="+post.getPostPhoto());
        });
        return new AjaxResult(200,"成功",list,total);
    }

    @GetMapping("/check")
    public AjaxResult check(int postId,String status)
    {
        int re = postService.check(postId,status);
        if (re != 0){
            return new AjaxResult(200,"成功");
        }else {
            return new AjaxResult(500,"失败");
        }
    }
   }
